package com.mall.controller;

import com.mall.common.pojo.JsonResult;
import com.mall.pojo.Menu;
import com.mall.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {

    // 查询一般返回查询到的数据
    // 删除和新增一般返回提示性的语句，删除成功和添加成功等。

    @Autowired
    private MenuService menuService;

    @RequestMapping("/doFindObjects")
    public JsonResult doFindObjects(){

        List<Map<String,Object>> list = menuService.findObjects();
        return new JsonResult(list);
    }


    //
    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        //int rows = menuService.deleteObject(id);
        menuService.deleteObject(id);
        return new JsonResult("删除成功！");
    }

    @RequestMapping("doFindZtreeMenuNodes")
    public JsonResult doFindZtreeMenuNodes(){
        return new JsonResult(menuService.findZtreeMenuNodes());
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(Menu entity){
        menuService.saveObject(entity);
        return new JsonResult("保存成功！");
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(Menu entity){
        menuService.updateObject(entity);
        return new JsonResult("更新成功！");
    }

}
